<template>
  <view class="container">
    <view class="title">请输入保单</view>
    <view class="table-box">
      <view class="table">
        <view class="tr">
          <view class="th">保费</view>
          <view class="th">缴费年限</view>
        </view>
        <view class="tr" v-for="(item, index) in list" :key="index">
          <input class="td" placeholder="请输入保费" type="digit" v-model="item.money"></input>
          <input class="td" placeholder="请输入缴费年限" type="number" maxlength="3" v-model="item.year"></input>
        </view>
      </view>
    </view>
    <view class="btn-box">
      <button class="btn" @click="addClick">
        <img class="icon" src="/static/add.png" alt="">
        <text>新增</text>
      </button>
      <button class="btn" @click="clacClick">
        <img class="icon" src="/static/calc.png" alt="">
        <text> 测算</text>
      </button>
    </view>
    <view class="text-box">
      <view class="text text-left">医康养财商</view>
      <view class="text text-right">法税教乐文</view>
    </view>
  </view>
</template>

<script setup>
import { ref } from 'vue'
let list = ref([]);
const addClick = () => {
  list.value.push({
    money: '',
    year: ''
  })
}

const clacClick = () => {
  let temp = list.value.filter(item => item.year && item.money)
  console.log('temp', temp);
  if (temp.length == 0) {
    uni.showToast({
      title: '请先输入保单！',
      duration: 2000
    })
    return
  }
  uni.showLoading({
    title: '正在计算中！',
  })
  list.value = temp;
  let total = 0;
  temp.forEach(item => {
    if (item.year >= 10) {
      total += Number(item.money)
    } else if (item.year < 10) {
      total += Number(item.money * item.year / 10)
    }
  })
  setTimeout(() => {
    uni.hideLoading();
    uni.navigateTo({
      url: `result?total=${total}`
    })
  }, 1000)
}

</script>

<style lang="scss" scoped>
.container {
  box-sizing: border-box;
  padding: 0 30rpx;
  position: relative;
  background: #f8f8f8;

  .title {
    font-family: PingFangSC-Medium;
    font-size: 36rpx;
    color: #333333;
    letter-spacing: -0px;
    text-align: center;
    font-weight: 500;
    line-height: 72rpx;
  }

  .table-box {
    max-height: 50vh;
    overflow: hidden;
    overflow-y: auto;
  }

  .table {
    width: 100%;
    box-sizing: border-box;
    border-radius: 8rpx;
    display: table;
    border: 1px solid #efefef;
    border-collapse: collapse;
    font-size: 28rpx;

    .th {
      text-align: center;
      color: #333333;
      padding: 20rpx 0;
      font-weight: bolder;
      display: table-cell;
      border: 1px solid #cccbcb;
      background-color: #f4f4f4;
    }

    .td {
      text-align: center;
      padding: 20rpx 0;
      display: table-cell;
      border: 1px solid #e3e3e3;
    }

    .tr {
      display: table-row;
    }
  }

  /* .table .tr:nth-child(1) {
		background-color: #f4f4f4;
	}
	.table .tr:nth-child(2) {
		background: linear-gradient(270deg, #ffffff 0%, #fff4e8 100%);
	}
	.table .tr:nth-child(3) {
		background: linear-gradient(270deg, #ffffff 0%, #e8f3ff 100%);
	}
	.table .tr:nth-child(4) {
		background: linear-gradient(270deg, #ffffff 0%, #ffeff2 100%);
	} */
  .btn-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 20rpx;

    .icon {
      width: 40rpx;
      height: 40rpx;
      margin-right: 10rpx;
    }

    .btn {
      background: #ffffff;
      border: 1rpx solid rgb(0, 128, 255);
      /* height: 96rpx; */
      font-family: PingFangSC-Regular;
      font-size: 32rpx;
      color: #414141;
      letter-spacing: 0;
      text-align: center;
      font-weight: 400;
      margin: 0;
      width: 48%;
      display: flex;
      align-items: center;
      justify-content: center;
      color: #016fff;
    }
  }

  .text-box {
    position: fixed;
    width: calc(100vw - 60rpx);
    bottom: 180rpx;

    .text {
      font-family: PingFangSC-Medium;
      font-size: 40rpx;
      color: #000;
      letter-spacing: -0px;
      text-align: center;
      font-weight: 500;
      line-height: 72rpx;
      width: 100%;
      letter-spacing: 53rpx;
      background: #fbf6f1;
      padding: 0 10px;
      border-radius: 8px;
      width: 100%;
      box-sizing: border-box;
      margin-bottom: 20rpx;
    }

    .text-left {
      text-align: left;
    }

    .text-right {
      text-align: right;
    }
  }
}
</style>
